<template>
  <!-- 重置密码dialog -->
  <el-dialog title="运费" :visible.sync="visible" width="40%">
    <el-tabs v-model="tableType" type="card" @tab-click="handelChangeType">
      <el-tab-pane label="设置运费" name="0"></el-tab-pane>
      <el-tab-pane label="历史运费单价" name="1"></el-tab-pane>
    </el-tabs>
    <div v-if="tableType == '0'">
      <p class="tootips">提示:首次设置当日生效，修改运费，系统默认次日生效</p>
      <el-form
        :model="priceForm"
        ref="priceForm"
        size="mini"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-form-item
          label="供应商名称"
          prop="supplierName"
          label-width="120px"
        >
          <el-input
            v-model.trim="priceForm.supplierName"
            placeholder="运费单价"
            style="width: 270px"
          >
            <template slot="append">元/公里</template>
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="loading" :data="teamList" v-if="tableType == '1'">
      <el-table-column label="有效日期" align="center" prop="ctime" />
      <el-table-column label="单价（元）/公里" align="center" prop="orderId" />
      <el-table-column label="设置人" align="center" prop="partsName" />
    </el-table>
    <pagination
      v-if="tableType == '1'"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <span slot="footer" class="dialog-footer">
      <el-button @click="handelCancel">关 闭</el-button>
      <el-button type="primary" @click="handleSubmit" v-if="tableType == '0'"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
  <script>
import { updateUser } from "@/api/system/user";
import QuickFilterDate from "@/components/QuickFilterDate";
import { inventoryRecord, addInventory } from "@/api/service/inventory";
export default {
  components: {
    QuickFilterDate,
  },
  data() {
    return {
      tableType: "0",
      initObj: {},
      visible: false,
      changeForm: {
        kc: "",
      },
      rules: {
        kc: [
          {
            required: true,
            message: "请输入",
            trigger: "change",
          },
        ],
      },

      dialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 排班管理表格数据
      teamList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 价格表单
      priceForm: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: "1",
        startTime: null,
        endTime: null,
        supplierName: null,
        concreteId: null,
        engineeringName: null,
      },
      times: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  props: {},
  computed: {},
  methods: {
    handelChangeType(val) {
      if (val == "1") {
        this.resetQuery();
      }
    },
    // 初始化函数--->父级调用
    handelInit(val) {
      console.log(val);
      this.initObj = val;
      this.visible = true;
      this.queryParams.id = val.id;
      this.getList();
    },
    handelCancel() {
      this.$refs.priceForm.resetFields();
      this.visible = false;
    },
    //
    handleSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.handleValidateSuccess();
        } else {
          return false;
        }
      });
    },
    handleValidateSuccess() {
      addInventory({
        ...this.formModel,
      }).then((res) => {
        console.log(res);
        this.handelCancel();
      });
    },
    /** 查询排班管理列表 */
    getList() {
      this.loading = true;
      inventoryRecord({
        ...this.queryParams,
      }).then((response) => {
        console.log("response--->", response);
        let { records, total } = response.data;
        this.teamList = records;
        this.total = total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  },
};
</script>
<style scoped lang="scss">
.tootips{
  font-size: 16px;
  padding-left: 36px;
  margin-bottom: 20px;
}
</style>